Skip to content

Add label selector support to exportTo field#35

Draft
hbhasker wants to merge 5 commits intomasterfrom
air-exportto-label-selectors
Draft

Add label selector support to exportTo field#35
hbhasker wants to merge 5 commits intomasterfrom
air-exportto-label-selectors

Conversation

@hbhasker
Copy link
Copy Markdown
Collaborator

Summary

Implements GitHub issue istio#50661 - Add label selector support to the exportTo field for VirtualService, DestinationRule, and ServiceEntry resources.

This allows services and configuration to be dynamically exported to namespaces matching label selectors, without requiring explicit namespace names.

Changes

API Changes (istio-api repo)

  • Added export_to_selectors field to VirtualService, DestinationRule, and ServiceEntry
  • Created LabelSelector type in type/v1beta1 for networking resources
  • Maintained backward compatibility by keeping LabelSelector in mesh/v1alpha1

Implementation (this repo)

  • ExportToTarget struct (pilot/pkg/model/exportto.go): Combines static namespaces with label selectors
  • ParseExportTo(): Converts API types to internal ExportToTarget
  • KubeNamespaceLabelsGetter: Implements namespace label lookup for visibility checks
  • Validation: Added validateExportToSelectors() for label selector validation
  • Integration: Updated push_context.go and conversion.go files to use new types

Example Usage

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: my-service
spec:
  hosts:
  - my-service
  exportTo:
  - "."  # Current namespace (static)
  exportToSelectors:
  - matchLabels:
      env: production  # Dynamic: all namespaces with env=production label
  - matchExpressions:
    - key: team
      operator: In
      values: [platform, infrastructure]

Test Plan

  • ExportToTarget unit tests
  • KubeNamespaceLabelsGetter tests
  • Validation tests for label selectors
  • All existing tests pass

Related

🤖 Generated with Claude Code

Bhasker Hariharan and others added 2 commits January 14, 2026 07:30
Phase 2: Core Model Changes
- Added ExportToTarget struct in pilot/pkg/model/exportto.go
- ParseExportTo function to convert API types to internal types
- LabelSelectorAsSelector for converting label selectors

Phase 3: ExportToFilter component
- Added exportto_filter.go in pkg/kube/namespace
- Watches namespace changes and caches labels for selector evaluation
- Provides MatchesSelector method for visibility checking

Phase 4: Validation changes
- Updated validateExportTo to handle exportToSelectors field
- Added validateExportToSelectors for label selector validation
- Validates operator types and expression values

Updated all references to use typev1beta1.LabelSelector to match
the refactored API types.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Phase 5-7: Integration Changes
- Updated push_context.go to use ParseExportTo() for VirtualService and DestinationRule
- Updated ServiceEntry conversion to parse exportToSelectors field
- Added support for exportTo annotation parsing in Kubernetes Service conversion
- Implemented KubeNamespaceLabelsGetter for namespace label lookup
- Wired up NamespaceLabelsGetter in bootstrap/server.go

Test Updates:
- Added comprehensive ExportToTarget unit tests (exportto_test.go)
- Added KubeNamespaceLabelsGetter tests (namespace_labels_test.go)
- Updated all test files to use typev1beta1.LabelSelector for MeshConfig
- Fixed TestServiceConversionWithExportToAnnotation for empty annotation handling

Files Added:
- pilot/pkg/model/exportto_test.go (394 lines)
- pilot/pkg/serviceregistry/kube/controller/namespace_labels.go (51 lines)
- pilot/pkg/serviceregistry/kube/controller/namespace_labels_test.go (127 lines)

Files Modified:
- pilot/pkg/model/push_context.go: VirtualService and DestinationRule use ParseExportTo
- pilot/pkg/serviceregistry/serviceentry/conversion.go: Parse exportToSelectors
- pilot/pkg/serviceregistry/kube/conversion.go: Handle exportTo annotation
- pilot/pkg/bootstrap/server.go: Wire up NamespaceLabelsGetter
- Multiple test files updated for type compatibility

Related to istio#50661

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Bhasker Hariharan and others added 3 commits January 14, 2026 23:04
…LabelSelector

MeshConfig fields (DiscoverySelectors, ServiceScopeConfigs) should use
the mesh.v1alpha1.LabelSelector type defined locally in config.proto,
not type.v1beta1.LabelSelector which is for networking API fields.

This aligns with the istio-api changes where config.pb.go was reverted
to keep LabelSelector types in the mesh/v1alpha1 package.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…ields

The LabelSelectorAsSelector helper functions in services.go and filter.go
need to use meshapi.LabelSelector (v1alpha1) not typev1beta1.LabelSelector
because they process MeshConfig.DiscoverySelectors and
MeshConfig.ServiceScopeConfigs which use the local mesh API LabelSelector type.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Use kclient.New[*corev1.Namespace](client) instead of
client.Kube().CoreV1().Namespaces() to create the namespace client
that implements kclient.Client[*corev1.Namespace].

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant